import React, { useState } from 'react';
import { Form, Input, Button, message, Table, Radio, Select, Modal, Upload } from 'antd'
import { UploadOutlined, InboxOutlined } from '@ant-design/icons';
// import { Form, Input, Button, Select, Image, message, Modal } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import { CloseOutlined } from '@ant-design/icons';
import { useEffect, setState } from 'react';
import './Timadd.scss'
import Avatar from './Upload'
import http from '../../utils/http'
const { Option } = Select;
const tailLayout = {
    wrapperCol: {
        offset: 8,
        span: 16,
    },
};
export const Timadd = (props) => {
    // 表单
    const [form2] = Form.useForm();
    const [form3] = Form.useForm();
    const [form4] = Form.useForm();
    const [selectdata, setSelectdata] = useState([])
    const { confirm } = Modal;
    useEffect(() => {
        let a = []
        http({
            url: '/peree_Comments/insertPereeCommentsInterface',
            method: 'post',
        }).then((res) => {
            console.log(res.data)
            if (res.code == 200) {
                //对数据进行处理
                let arr = res.data.map((v, i) => {
                    return {
                        key: v.roomId,
                        roomNo: v.roomNo,
                        tenId: v.tenId
                    }
                })
                console.log(arr)
                setSelectdata(arr)
                console.log(selectdata)
            }
        })

    }, [])
    const normFile = (e) => {
        console.log('Upload event:', e);

        if (Array.isArray(e)) {
            return e;
        }

        return e && e.fileList;
    };
    const quxiao = () => {
        confirm({
            icon: <ExclamationCircleOutlined />,
            content: '您确定离开此页面吗？',
            cancelText: '取消',
            okText: '确定',
            onOk() {
                //   console.log('OK');
                backCar()
            },
            onCancel() {
                console.log('Cancel');
            },
        });
    }
    const backCar = () => {
        props.setState(1)
    }
    // 文本框
    const { TextArea } = Input;
    // 返回父级
    const BuildingReturn = () => {
        console.log(props)
        props.setState(1)
    }
    const onFinish = (values) => {
        let a = {}
        console.log(values)
        for (let key in form2.getFieldsValue(true)) {
            a[key] = form2.getFieldsValue(true)[key]
        }
        for (let key in form3.getFieldsValue(true)) {
            a[key] = form3.getFieldsValue(true)[key]
        }
        for (let key in form4.getFieldsValue(true)) {
            a[key] = form4.getFieldsValue(true)[key]
        }
        console.log(a)
        http({
            url: '/peree_Comments/insertPeree',
            params: a,
        }).then((res) => {
            console.log(res)
            if (res.code == 200) {
                setState(1)
                message.success('添加成功！');
            }
            else {
                message.error('添加失败！')
            }
        })
    }
    return (
        <div className='buildingAdd_box'>
            {/* 顶层样式 */}
            <Form name="horizontal_login" layout="inline" className='title' onFinish={onFinish}>
                <Form.Item
                    name="username">
                    <div className='kuai'>
                        <span></span>
                        <span>租户信息新增</span>
                    </div>
                </Form.Item>
                <Form.Item className='btn'>
                    <div>
                        <CloseOutlined onClick={BuildingReturn} style={{ fontSize: 20, cursor: " pointer" }} />
                    </div>

                </Form.Item>
            </Form>

            <div className='biao timaddbiao'>
                {/* 上 */}
                <div style={{ display: "flex" }}>
                    {/* 左边文字 */}
                    <div className='buildingAdd_biao_left'>
                        <h2>基本信息</h2>
                    </div>
                    {/* 右边内容 */}
                    <div className='buildingAdd_biao_right'>
                        {/* 左边表单 */}
                        <div className='buildingAdd_biao_childleft'>
                            <Form
                                onFinish={onFinish}
                                name="basic"
                                initialValues={{ remember: true }}
                                autoComplete="off"
                                form={form2}
                                className='timaddfrom'
                            >

                                <div >

                                    <Form.Item
                                        label="租户名称"
                                        name="perName"
                                        rules={[{ required: true }]}
                                    >
                                        <Input placeholder="请输入租户名称" />
                                    </Form.Item>

                                    <Form.Item
                                        label="所属楼宇"
                                        name='tenSerialint'
                                        rules={[{ required: true }]}
                                    >
                                        <Select>
                                            <Select.Option value="A1幢">
                                                A1幢
                                            </Select.Option>
                                            <Select.Option value="B2幢">
                                                B2幢
                                            </Select.Option>
                                            <Select.Option value="C3幢">
                                                C3幢
                                            </Select.Option>
                                        </Select>
                                    </Form.Item>
                                    <Form.Item
                                        label="房间名称"
                                        name="roomNo"
                                        rules={[{ required: true }]}
                                        style={{
                                            flex: '1',
                                        }}

                                    >
                                        {/* <Input placeholder="请输入房间名称" /> */}
                                        <Select placeholder="请选择房间名称">
                                            {selectdata.map((item) =>
                                                <Option value={item.key} key={item.key}>{item.roomNo}</Option>
                                            )}
                                        </Select>
                                    </Form.Item>
                                </div>

                                <div>
                                    <Form.Item
                                        label="社会信用代码"
                                        name="perSocialcode"
                                        rules={[{ required: true }]}
                                        style={{
                                            flex: '1',
                                        }}
                                    >
                                        <Input placeholder="请输入统一社会信用代码" />
                                    </Form.Item>

                                    <Form.Item
                                        name='perIndustry'
                                        label="所属行业"
                                        rules={[{ required: true }]}
                                    >
                                        <Select>
                                            <Select.Option value="0">
                                                信息传输、软件和信息技术务业
                                            </Select.Option>
                                            <Select.Option value="1">
                                                金融业
                                            </Select.Option>
                                            <Select.Option value="2">
                                                住宿和餐饮业
                                            </Select.Option>
                                        </Select>
                                    </Form.Item>
                                    <Form.Item
                                        name='perLarge'
                                        label="企业规模"
                                        rules={[{ required: true }]}
                                    >
                                        <Select>
                                            <Select.Option value="0">
                                                特大型
                                            </Select.Option>
                                            <Select.Option value="1">
                                                大型
                                            </Select.Option>
                                            <Select.Option value="2">
                                                中型
                                            </Select.Option>
                                        </Select>
                                    </Form.Item>
                                </div>
                                <div>
                                    <Form.Item
                                        label="注册资金"
                                        name="perMoney"
                                        rules={[{ required: true }]}
                                        style={{
                                            flex: '1',
                                        }}
                                    >
                                        <Input placeholder="请输入注册资金" />
                                    </Form.Item>



                                    <Form.Item
                                        name='perIsnew'
                                        label="是否高新"
                                        rules={[{ required: true }]}
                                    >
                                        <Select>
                                            <Select.Option value="0">
                                                是
                                            </Select.Option>
                                            <Select.Option value="1">
                                                否
                                            </Select.Option>
                                        </Select>
                                    </Form.Item>
                                    <Form.Item
                                        name='perListed'
                                        label="是否上市"
                                        rules={[{ required: true }]}
                                    >
                                        <Select>
                                            <Select.Option value="0">
                                                是
                                            </Select.Option>
                                            <Select.Option value="1">
                                                否
                                            </Select.Option>
                                        </Select>
                                    </Form.Item>
                                </div>
                                <div>
                                    <Form.Item
                                        label="企业估值"
                                        name="perValuation"
                                        rules={[{ required: true }]}
                                        style={{
                                            flex: '1',
                                        }}
                                    >
                                        <Input placeholder="请输入企业估值" />
                                    </Form.Item>

                                    <Form.Item label="营业执照"
                                        name="perLicense"
                                        rules={[{ required: true }]}
                                        style={{
                                            flex: '1',
                                        }}>
                                        <Avatar></Avatar>
                                    </Form.Item>
                                    <Form.Item label="企业LOGO"
                                        name="perLogo"
                                        rules={[{ required: true }]}
                                        style={{
                                            flex: '1',
                                        }}>
                                        <Avatar></Avatar>
                                    </Form.Item>
                                </div>

                            </Form>
                        </div>
                    </div>
                </div>

                {/* 下 */}
                <div style={{ display: "flex" }}>
                    <div className='timaddbottonleft' style={{ display: "flex", marginTop: "25px", flex: '1', marginRight: '12px' }}>
                        {/* 左边文字 */}
                        <div className='buildingAdd_biao_left'>
                            <h2 style={{ lineHeight: "40px" }}>负责人信息</h2>
                        </div>
                        {/* 右边内容 */}
                        <div className='buildingAdd_biao_right' style={{ padding: "1.5% 1%" }}>
                            {/* 左边表单 */}
                            <div>

                                <Form
                                    onFinish={onFinish}
                                    name="basic"
                                    initialValues={{ remember: true }}
                                    autoComplete="off"
                                    form={form3}
                                    className='timaddfrom2'
                                >
                                    <div>
                                        <Form.Item
                                            label="负责人姓名"
                                            name="personName"
                                            rules={[{ required: true }]}
                                        >
                                            <Input placeholder="请输入负责人姓名" />
                                        </Form.Item>
                                        <Form.Item name="personSex" label="性别" rules={[{ required: true }]}>

                                            <Radio.Group>
                                                <Radio value="0">男</Radio>
                                                <Radio value="1">女</Radio>
                                            </Radio.Group>
                                        </Form.Item>
                                    </div>
                                    <div>
                                        <Form.Item
                                            label="联系方式"
                                            name="personPhone"
                                            rules={[{ required: true }]}
                                        >
                                            <Input placeholder="请输入联系方式" />
                                        </Form.Item>
                                        <div></div>
                                    </div>
                                    <div>

                                        <Form.Item label="用户头像"
                                            name="personPhoto"
                                            rules={[{ required: true }]}>
                                            <Avatar></Avatar>
                                        </Form.Item>
                                        <div></div>
                                    </div>

                                </Form>

                            </div>
                        </div>
                    </div>
                    <div className='timaddbottonleft' style={{ display: "flex", marginTop: "25px", flex: '1' }}>
                        {/* 左边文字 */}
                        <div className='buildingAdd_biao_left'>
                            <h2 style={{ lineHeight: "40px" }}>负责人信息</h2>
                        </div>
                        {/* 右边内容 */}
                        <div className='buildingAdd_biao_right' style={{ padding: "1.5% 1%" }}>

                            <Form
                                onFinish={onFinish}
                                name="basic"
                                initialValues={{ remember: true }}
                                autoComplete="off"
                                form={form4}
                                className='timaddfrom2'
                                style={{ width: "100%" }}
                            >
                                <div style={{ width: "100%" }} >
                                    <Form.Item
                                        label="合同编号"
                                        name="contract_Serial"
                                        rules={[{ required: true }]}
                                    >
                                        <Input />
                                    </Form.Item>
                                    <div></div>
                                </div>
                                <div>
                                    <Form.Item
                                        label="银行卡号"
                                        name="collNum"
                                        rules={[{ required: true }]}
                                    >
                                        <Input placeholder="请输入银行卡号" />
                                    </Form.Item>
                                    <div></div>
                                </div>
                                <div>
                                    <Form.Item label="合同凭证"
                                        name="contract_credentials"
                                    // rules={[{ required: true }]}
                                    >
                                        <Avatar></Avatar>
                                    </Form.Item>
                                    <Form.Item label="转账凭证"
                                        name="credentials"
                                    // rules={[{ required: true }]}
                                    >
                                        <Avatar></Avatar>
                                    </Form.Item>
                                </div>

                            </Form>

                        </div>
                    </div>

                </div>
                <Form
                    onFinish={onFinish}
                    name="basic"
                    autoComplete="off"
                    form={form4}
                    style={{ marginTop: '28px' }}
                >
                    <Form.Item {...tailLayout} className='mybutton'>
                        <div className='btn'>
                            <Button type="primary" htmlType="submit" >
                                保存
                            </Button>
                            <Button onClick={quxiao}>
                                取消
                            </Button>
                        </div>
                    </Form.Item>
                    {/* 保存取消 */}
                </Form>

            </div >
        </div >
    )
}


export default Timadd